//
//  AIWheelPlayerView.m
//  aixianfeng
//
//  Created by wangwei on 2016/12/22.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "AIWheelPlayerView.h"
#import <Foundation/Foundation.h>
#import "AIHomeFocusModel.h"
#import "AIHomeWheelPlayerActionController.h"

@interface AIWheelPlayerView()

@property (nonatomic,strong)NSMutableArray<NSString *> *urlStringArray;
@property (nonatomic,strong)NSMutableArray<NSString *> *toURLStringArray;

@property (nonatomic,strong)SDCycleScrollView *cycleScrollView;

@end

@implementation AIWheelPlayerView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //设置UI界面
        [self setupUI];
        
    }
    return self;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        [self setupUI];
    }
    return self;
}

//设置UI界面
- (void)setupUI {
    NSMutableArray <NSString *> *urlStringArray = [NSMutableArray array];
    NSMutableArray <NSString *> *toURLStringArray = [NSMutableArray array];
    
    for (AIHomeFocusModel *model in self.focusModelArray) {
        [urlStringArray addObject:model.img];
        [toURLStringArray addObject:model.toURL];
    }
    
    self.urlStringArray = urlStringArray;
    self.toURLStringArray = toURLStringArray;
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.frame delegate:self placeholderImage:[UIImage imageNamed:@""]];
    [self addSubview:cycleScrollView];
    self.cycleScrollView = cycleScrollView;
    [self layoutIfNeeded];
    //属性
    cycleScrollView.imageURLStringsGroup = self.urlStringArray;
    cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
    cycleScrollView.showPageControl = YES;
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    cycleScrollView.currentPageDotColor = [UIColor greenColor];
    cycleScrollView.pageDotColor = [UIColor purpleColor];

}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    //这里是点击图片跳转控制器
    
    //这里我们需要创建控制器实现跳转
    AIHomeWheelPlayerActionController *cv = [AIHomeWheelPlayerActionController new];
    cv.toURL = self.toURLStringArray[index];
    
    [[self findNavController] pushViewController:cv animated:YES];
    
    
    
}

- (void)setFocusModelArray:(NSArray<AIHomeFocusModel *> *)focusModelArray {
    _focusModelArray = focusModelArray;

    for (AIHomeFocusModel *model in self.focusModelArray) {
        [self.urlStringArray addObject:model.img];
        [self.toURLStringArray addObject:model.toURL];
    }
    
    [self setupUI];
}


@end









